package com.thinksns.sociax.t4.adapter;

import android.content.Context;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.thinksns.sociax.android.R;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by zhiyicx on 2017/5/2.
 */

public class EventPopListAdapter extends BaseAdapter {

    private Context context;
    private LayoutInflater inflater;
    private List<String> datas;

    public EventPopListAdapter(Context context){
        this.context = context;
        inflater = LayoutInflater.from(context);
        datas = new ArrayList<>();
    }

    public void setDatas(List<String> datas){
        this.datas.clear();
        this.datas.addAll(datas);
        notifyDataSetChanged();
    }

    public void insertDatas(List<String> datas){
        this.datas.addAll(datas);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return datas == null ? 0 : datas.size();
    }

    @Override
    public Object getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view == null){
            view = inflater.inflate(R.layout.event_pop_list_item,null);
            viewHolder = new ViewHolder();
            viewHolder.convert_tv = (TextView) view.findViewById(R.id.pop_event_item_tv);
            viewHolder.convert_tv.setText(datas.get(i));
            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) view.getTag();
            viewHolder.convert_tv.setText(datas.get(i));
        }
        return view;
    }

    public class ViewHolder{
        TextView convert_tv;
    }
}
